package com.bitdf.txing.chat.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.bitdf.txing.chat.entity.GroupEntity;
import com.bitdf.txing.chat.service.GroupService;
import com.bitdf.txing.common.utils.PageUtils;
import com.bitdf.txing.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;




/**
 * 
 *
 * @author lzw
 * @email 123@qq.com
 * @date 2022-11-23 22:43:49
 */
@RestController
@RequestMapping("${txing.request.path.chat}/group")
public class GroupController {
    @Autowired
    private GroupService groupService;

    /**
     * 列表
     */
    @SaCheckLogin
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = groupService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @SaCheckLogin
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		GroupEntity group = groupService.getById(id);

        return R.ok().put("group", group);
    }

    /**
     * 保存
     */
    @SaCheckLogin
    @RequestMapping("/save")
    public R save(@RequestBody GroupEntity group){
		groupService.save(group);

        return R.ok();
    }

    /**
     * 修改
     */
    @SaCheckLogin
    @RequestMapping("/update")
    public R update(@RequestBody GroupEntity group){
		groupService.updateById(group);

        return R.ok();
    }

    /**
     * 删除
     */
    @SaCheckLogin
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		groupService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
